n = int(input())

s_sum = 0
s = [int(i) for i in input().split()]

s_sum = sum(s)

chayi = -1
AB_min = 0

for i in range(n):
    A = 0
    for j in range(i,n+i):
        A += s[j%n]

        if chayi==-1:
            chayi = abs(s_sum-2*A)
            AB_min=min(A,s_sum-A)
        elif chayi>abs(s_sum-2*A):
            chayi = abs(s_sum-2*A)
            AB_min=min(A,s_sum-A)


print("{:.0f}".format(AB_min))
# 会超时
        
